<template>
  <el-dialog :title="add" :visible.sync="dialogFormVisible" width="30%">
    <el-form :model="form">
      <el-form-item label="分类名称:" :label-width="formLabelWidth">
        <el-input v-model="form.name" autocomplete="off"  @keyup.enter.native="sendData"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer" style="display: flex;align-items: center;justify-content: center">
      <el-button @click="dialogFormVisible = false" style="margin-right: 10px">取 消</el-button>
      <el-button type="primary" @click="sendData">保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
/*eslint-disable*/
import {addData,checkOnly} from "@/utils/category"
  export default {
    name: "addCategory",
    data(){
      return{
        add:'',
        dialogFormVisible: false,
        form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        formLabelWidth: '100px'
      }
    },
    methods: {
      changeVisible(add) {
        this.add=add;
        this.dialogFormVisible=true
      },
     async sendData(){
        if (this.form.name==""){
          console.log("查询空");
          return
        }else{
          console.log(this.form.name);
          this.dialogFormVisible=false
          let res=await checkOnly(`/porcelainType/check/${this.form.name}`)
          if (res.data.length<=0){
            addData(`/porcelainType/${this.form.name}`)
              .then(rawRes=>rawRes.data)
              .then(res=>{
                this.$emit('sendDate',res)
              })
            this.$message({
              message: '添加的成功',
              type: 'success'
            });
          }else{
            this.$message({
              message: '添加的已存在,请重新添加',
              type: 'warning'
            });
            return
          }
        }
      }
    },
  }
</script>

<style scoped>

</style>
